package com.dayuanit.spring.demo.controller;

import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

//Controller注解包含了Component注解，像这样的注解标签，称之为复合标签
@Controller
public class AnimalController {

    public AnimalController() {
        System.out.println("AnimalController()");
    }

    /**
     * 服务器内部跳转
     * @return
     */
    @RequestMapping(value = "/animal/toHome")
    public String toHome() {
        return "home";
    }

    /**
     * 重定向
     * @return
     */
    @RequestMapping(value = "/animal/toTaobao")
    public String toTaobao() {
        return "redirect:http://www.taobao.com";
    }


    /**
     * 响应json串
     * @return
     */
    @RequestMapping(value = "/animal/listNames")
    @ResponseBody
    public List<String> listNames() {
        ArrayList<String> list = new ArrayList<>();
        list.add("fish");
        list.add("cat");
        list.add("dog");
        System.out.println("listNames()");
        return list;
    }
}
